package com.iscale.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.iscale.model.dto.Pager;
import com.iscale.model.entity.SysUser;
import com.iscale.mapper.SysUserMapper;
import com.iscale.service.SysUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.iscale.util.StringUtil;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Andychen
 * @since 2017-03-01
 */
@Service
@Transactional
public class SysUserServiceImpl extends ServiceImpl<com.baomidou.mybatisplus.mapper.BaseMapper<SysUser>, SysUser> implements SysUserService {

    @Autowired
    SysUserMapper userMapper;

    @Override
    public Pager<SysUser> selectUserByPage(int page, int size, String orderByFields,boolean isAsc) {
        RowBounds bounds = new RowBounds(page-1,size);
        EntityWrapper<SysUser> entityWrapper = new EntityWrapper<>(new SysUser());
        entityWrapper.where("status={0}",0);
        if(StringUtil.isNotEmpty(orderByFields)){
            entityWrapper.orderBy(orderByFields,isAsc);
        }
        List<SysUser> ls =  baseMapper.selectPage(bounds,entityWrapper);
        Integer count = baseMapper.selectCount(entityWrapper);
        return new Pager<>(count,ls);
    }


}
